package org.jadapter.registry;

import org.jadapter.Adapter;
import org.jadapter.AdapterFactory;
import org.jadapter.func.Lambda;

/**
 * The main interface to the JAdapter API for client code.
 * Provides methods both to register adapters, and more importantly, 
 * to use them.
 * 
 * This needs more documentation.
 * 
 * @author Vidar Svansson
 * @since 0.1
 * 
 * @see AbstractAdapterRegistry
 * @see TransitiveAdapterRegistry
 */
public interface AdapterRegistry {
        
    /** 
     * Get an instance of the given some context object 
     * This is the main method.
     * 
     * @param type The desired type to transform to.
     * @param context The object to transform.
     * 
     * @return an instance of T if it is possible to transform
     * the context to the type.
     * 
     * @since 0.1
     */
    public  <T> T adapt(Class<T> type, Object context) ;
    
    /** 
     * Get a named instance of the given some context object.
     * Currently only available in {@link SimpleComponentRegistry}. 
     * @since 0.1
     */
    public  <T> T adapt(Class<T> type, Object context, String name) ;
   
    /** 
     * Register a framework adapter 
     * @param adapter The adapter to register.
     */
    public  void register(AdapterFactory<?,?> ... adapters);
    
    /**
     * Register a class that by reflection can act as an adapter. 
     * @param provides The type provided by this adapter.
     * @param adapter The adapter class. 
     * @param adaptable The supported input type.
     */
    public  <I,C> void register(
            Class<I> provides, 
            Class<?> adapter,
            Class<C> adaptable) ;
    
    /**
     * Register a function as an adapter.
     * @param provides The type provided by this adapter.
     * @param adapter The function to register.
     * @param context The supported input type.
     */
    public  <I,C> void register(
            Class<I> provides,
            Lambda<I,C> adapter,
            Class<C> context);
    
    /**
     * 
     * Register an adapter that does not implement {@link org.jadapter.AdapterFactory}
     * 
     * @since 0.1
     */
    public  <I,C> void register(
            Class<I> provides, 
            Adapter<I,C> adapter, 
            Class<C> adaptable) ; 
    
    /** 
     * Register multiple adapters.
     * @param adapters Adapters to register.
     * @since 0.1
     */
    public void registerAdapters(Iterable<AdapterFactory<?,?>> adapters);  
    

}
